package com.hiwhitley.himei.module.game;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hiwhitley.himei.R;
import com.hiwhitley.himei.entity.GamePoster;
import com.hiwhitley.himei.widget.glide.GlideImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.drakeet.multitype.ItemViewProvider;

/**
 * Created by hiwhitley on 17-2-26.
 */
public class GamePostersViewProvider
        extends ItemViewProvider<GamePoster, GamePostersViewProvider.ViewHolder> {

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_game_poster, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull GamePoster gamePosters) {
        holder.mGamePoster.loadNetImage(gamePosters.getGamePoster(), R.drawable.bg_holder_brown);
        holder.root.setOnClickListener(v -> {
            Context context = holder.root.getContext();
            Intent intent = GameDetailActivity.newIntent(context, gamePosters.getGid(), gamePosters.getGameName());
            context.startActivity(intent);
        });
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.game_poster)
        GlideImageView mGamePoster;
        View root;
        ViewHolder(View itemView) {
            super(itemView);
            root = itemView;
            ButterKnife.bind(this, itemView);
        }
    }
}